buffer: improve fill(number) performance#31489
Conversation
lib/buffer.js
Outdated
There was a problem hiding this comment.
| const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8Array.prototype); | |
| const Uint8ArrayPrototype = ObjectGetPrototypeOf(Uint8Array.prototype); |
Uint8Array.prototype.constructor.name is Uint8Array, not TypedArray.
There was a problem hiding this comment.
This line is correct as-is. The prototype of Uint8Array.prototype is the %TypedArray%.prototype.
There was a problem hiding this comment.
@devsnek is correct, this is the prototype of the prototype, which is TypedArray. The same thing is done in internal/util/types.js.
039c099 to
aa45188
Compare
|
I think we could also directly add TypedArray and its prototype to the primordials. I'll do that after this PR. |
aa45188 to
ac9de4f
Compare
lib/buffer.js
Outdated
There was a problem hiding this comment.
Future enhancement: res < 0 is sometimes a coercion-to-nan, sometimes not because bindingFill() returns either undefined or a number.
Changing Fill() in node_buffer.cc to always return a number is probably beneficial for performance.
PR-URL: nodejs#31489 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
ac9de4f to
59cba9a
Compare
|
This seems to have landed without first getting a clean CI run. |
Although if there was an impressive-benchmarks-mean-you-can-land-without-a-clean-CI rule, this would definitely qualify. 😍 |
PR-URL: #31489 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #31489 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #31489 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Uses the native
typedArray.fill()when filling with a number instead of calling into the binding fill function.Benchmark results:
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes